package cn.howxu.yichen_ovo.init;

import cn.howxu.yichen_ovo.YiChenOVO;
import cn.howxu.yichen_ovo.common.item.*;
import cn.howxu.yichen_ovo.common.item.api.PaintItem;
import cn.howxu.yichen_ovo.common.item.cd.*;
import cn.howxu.yichen_ovo.common.item.kkx_cd.KkxFrxCD;
import cn.howxu.yichen_ovo.common.item.kkx_cd.KkxLoveCD;
import cn.howxu.yichen_ovo.common.item.kkx_cd.KkxSadCD;
import cn.howxu.yichen_ovo.common.item.paint.BXLPaint;
import cn.howxu.yichen_ovo.common.item.paint.BuDaiPaint;
import cn.howxu.yichen_ovo.common.item.paint.EYEPaint;
import cn.howxu.yichen_ovo.common.item.paint.OUTPaint;
import net.minecraft.world.item.*;
import net.minecraftforge.registries.DeferredRegister;
import net.minecraftforge.registries.ForgeRegistries;
import net.minecraftforge.registries.RegistryObject;

import java.util.LinkedList;
import java.util.List;
import java.util.function.Supplier;

/**
 * @description: TODO
 * @author: HowXu
 * @date: 2025/9/12 18:04
 */
public class ModItems {

    public static final DeferredRegister<Item> REGISTER = DeferredRegister.create(ForgeRegistries.ITEMS, YiChenOVO.MODID);
    public static final List<RegistryObject<? extends Item>> ITEMS = new LinkedList<>();
    public static final List<RegistryObject<? extends Item>> RECORDS = new LinkedList<>();
    public static final List<RegistryObject<? extends Item>> BLOCK_ITEMS = new LinkedList<>();
    public static final List<RegistryObject<? extends Item>> EGGS = new LinkedList<>();
    public static final List<RegistryObject<? extends Item>> TABS = new LinkedList<>();
    public static final List<RegistryObject<? extends Item>> PAINTS = new LinkedList<>();

    public static RegistryObject<Item> DOLL_ENTITY_ITEM = REGISTER.register("item_doll_entity", DollEntityItem::new);
    public static RegistryObject<Item> ATMStar = regItem("atmstar", ATMStar::new);
    public static RegistryObject<Item> YangYuBa = regItem("yangyuba", YangYuBa::new);
    public static RegistryObject<Item> COLDEGG = regItem("coldegg", ColdEgg::new);
    public static RegistryObject<Item> CRAFTING = regBlock("crafting", () -> new BlockItem(ModBlocks.CRAFTING.get(), new Item.Properties()));
    public static RegistryObject<Item> UL = regBlock("ul", () -> new BlockItem(ModBlocks.UL.get(), new Item.Properties()));
    public static RegistryObject<Item> MEGACELL = regItem("mega_cell", MegaCell::new);
    public static RegistryObject<Item> DENGPAI = regItem("dengpai", DengPai::new);

    public static RegistryObject<Item> RECORD_WA = regRecord("record_wa", WA::new);
    public static RegistryObject<Item> RECORD_LZ = regRecord("record_lz", LZ::new);
    public static RegistryObject<Item> RECORD_SWEET = regRecord("record_sweet", Sweet::new);
    
    public static RegistryObject<Item> RECORD_KKX_LOVE = regRecord("record_kkx_love", KkxLoveCD::new);
    public static RegistryObject<Item> RECORD_KKX_SAD = regRecord("record_kkx_sad", KkxSadCD::new);
    public static RegistryObject<Item> RECORD_KKX_FRX = regRecord("record_kkx_frx", KkxFrxCD::new);

    public static RegistryObject<Item> EGG_1X = regEgg(1);
    public static RegistryObject<Item> EGG_2X = regEgg(2);
    public static RegistryObject<Item> EGG_3X = regEgg(3);
    public static RegistryObject<Item> EGG_4X = regEgg(4);
    public static RegistryObject<Item> EGG_5X = regEgg(5);
    public static RegistryObject<Item> EGG_6X = regEgg(6);
    public static RegistryObject<Item> EGG_7X = regEgg(7);
    public static RegistryObject<Item> EGG_8X = regEgg(8);
    public static RegistryObject<Item> EGG_9X = regEgg(9);

    public static RegistryObject<Item> TIELI = regItem("tieli", TieLi::new);
    public static RegistryObject<Item> HEART = regItem("heart", Heart::new);

    public static RegistryObject<Item> ALBOOK = regSpecial("albook", ()->new ALBookItem(ModBlocks.ALBOOK.get()));

    public static RegistryObject<Item> SWORD = regSpecial("sword", Sword::new);
    public static RegistryObject<Item> FLAG = regSpecial("flag", () -> new BlockItem(ModBlocks.FLAG.get(), new Item.Properties().rarity(Rarity.RARE)));

    public static RegistryObject<Item> SPAWN = regItem("spawn", Spawn::new);
    public static RegistryObject<Item> WYG = regItem("wyg", WYG::new);

    public static RegistryObject<Item> WINE = regSpecial("wine", ()->new WineItem(ModBlocks.WINE.get()));
    
    public static RegistryObject<Item> BUDAI_PAINT = regPainting("budai_paint", BuDaiPaint::new);
    public static RegistryObject<Item> OUT_PAINT = regPainting("out_paint", OUTPaint::new);
    public static RegistryObject<Item> BXL_PAINT = regPainting("bxl_paint", BXLPaint::new);
    public static RegistryObject<Item> EYE_PAINT = regPainting("eye_paint", EYEPaint::new);
    

    private static RegistryObject<Item> regItem(String name, Supplier<? extends Item> sup) {
        RegistryObject<Item> e = REGISTER.register(name, sup);
        ITEMS.add(e);
        return e;
    }

    private static RegistryObject<Item> regBlock(String name, Supplier<? extends Item> sup) {
        RegistryObject<Item> e = REGISTER.register(name, sup);
        BLOCK_ITEMS.add(e);
        return e;
    }

    private static RegistryObject<Item> regRecord(String name, Supplier<? extends Item> sup) {
        RegistryObject<Item> e = REGISTER.register(name, sup);
        RECORDS.add(e);
        ITEMS.add(e);
        return e;
    }

    private static RegistryObject<Item> regEgg(int level) {
        RegistryObject<Item> e = REGISTER.register("egg_" + level + "x", () -> new EGG(level));
        ITEMS.add(e);
        EGGS.add(e);
        return e;
    }

    private static RegistryObject<Item> regSpecial(String name, Supplier<? extends Item> sup) {
        RegistryObject<Item> e = REGISTER.register(name, sup);
        TABS.add(e);
        return e;
    }

    private static RegistryObject<Item> regPainting(String name, Supplier<? extends Item> sup) {
        RegistryObject<Item> e = REGISTER.register(name, sup);
        TABS.add(e);
        PAINTS.add(e);
        return e;
    }
}
